﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using EventMgrLib;
using SmartMotion.Core;
using WeifenLuo.WinFormsUI.Docking;

namespace SmartMotion.AllPages.DockPanels
{
    public partial class FrmProperty : DockContent
    {
        private EventMgr _em;

        #region 构造和Load

        public FrmProperty()
        {
            InitializeComponent();
            HideOnClose = true;
        }

        private void FrmProperty_Load(object sender, EventArgs e)
        {
            _em = EventMgr.Ins;
            _em.GetEvent<SelectActionChanged>().Subscribe(ObjChanged);
            _em.GetEvent<SelectFlowChanged>().Subscribe(FlowChanged);
        }

        #endregion

        #region 属性显示与绑定

        private void FlowChanged(Flow obj)
        {
            propertyGrid1.SelectedObject = obj;
        }

        private void ObjChanged(ActionItem obj)
        {
            if (propertyGrid1.SelectedObject == obj)
            {
                propertyGrid1.Refresh();
            }
            else
            {
                propertyGrid1.SelectedObject = obj;
            }
            
        }

        private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            //EventMgr.Ins.GetEvent<PropertyValueChanged>().Publish();
        }

        #endregion
    }
}
